// import axios from '../../utils/http';
import axios from 'axios';
export default {
    namespaced: true,
    state: {
        a: 1,
        c: [],
        b: [],
        d: '',
        product: [],
        table: [],
        tableAll: [],
        mode: [],
        queue: [],
        food: [],
        line: ''
    },
  actions: {
    line (a, value) {
      axios({
        url: "/xjh/product/line",
      }).then((res) => {
        a.commit('number', res.data.data.pop())
      }).catch((err) => {
        console.log(err, '错误')
      });
    },
    actions: {
        line(a, value) {
            axios({
                url: "/api/product/line",
            }).then((res) => {
                a.commit('number', res.data.data.pop())
            }).catch((err) => {
                console.log(err, '错误')
            });
        },
        queue(a, value) {
            console.log('成功', a, value)
            axios({
                url: "/api/numeralorder/queue",
            }).then((res) => {
                console.log(res.data.data)
                a.state.queue = res.data.data
            });
        },
        jia(a, value) {
            axios({
                url: "/api/coupon/xjh/manage/coupon",
            }).then((res) => {
                a.state.c = res.data.data
            });
        },
        jiaA(a, value) {

            axios({
                url: "/api/product/xjh/manage/Product",
            }).then((res) => {
                console.log(res)
                a.state.product = res.data.data
            }).catch((err) => {
                console.log(err)
            });
        },
        table(a, value) {

            axios({
                url: "/api/tablelist/gettablearea",
            }).then((res) => {
                a.state.table = res.data.data
            }).catch((err) => {
                console.log(err)
            });
        },
        tableAll(a, value) {
            console.log('成功运行1111', a, value)
            axios({
                url: "/api/tablelist/gettableAll",
            }).then((res) => {
                console.log(res)

                a.commit('change', res.data.data)

        a.commit('change', res.data.data)

            });
        },
        send(a, value) {
            // console.log('成功运行1111', a, value)
            axios({
                url: "/api/coupon/xjh/manage/coupon/change",
                params: value
            }).then(async (res) => {
                await a.dispatch('jia')
                a.state.d = res.data.msg
            }).catch((err) => {
                console.log(err)
            })
        },
        sendTwo(a, value) {
            console.log('成功运行1111', a, value)
            axios({
                url: "/api/product/sendTwo",
                params: value
            }).then(async (res) => {
                await a.dispatch('jiaA', 'over', 'food', 'line')
                a.state.d = res.data.msg
            }).catch((err) => {
                console.log(err)
            })
        },
        over(a, value) {
            axios({
                url: "/api/product/xjh/manage/Product/pro",
                params: value
            }).then(async (res) => {
                await a.dispatch('jiaA')
                a.state.d = res.data.msg
            }).catch((err) => {
                console.log(err)
            })
        },
        food(a, value) {
            axios({
                url: "/api/product/xjh/manage/Product/food",
                params: value
            }).then(async (res) => {
                console.log(22222);
                console.log(res.data.data)
                await a.dispatch('jiaA')
                a.state.food = res.data.data
            }).catch((err) => {
                console.log(err)
            })
        },

  },
  mutations: {
    change (state, n) {
      state.tableAll = []
      state.mode = []
      n.forEach((v) => {
        state.tableAll.push(v.table_num)
        state.mode.push(v.table_state)
      })
    },
    number (state, n) {
      if ((n.pack_rank) * 1 + 1 < 100) {
        state.line = '0' + ((n.pack_rank) * 1 + 1)
      } else {
        (n.line_num) * 1 + 1
      }
    }
  }
  }
}